//
//  Seach_FiltrateAttributeSup_Tbv_WX.m
//  ZITHER
//
//  Created by weixin on 2019/3/27.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Seach_FiltrateAttributeSup_Tbv_WX.h"
#import "Seach_FiltrateAttributeSup_Cell_WX.h"

@implementation Seach_FiltrateAttributeSup_Tbv_WX


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self def];
        [self setUI];
        [self setMasonry];
    }
    return self;
}

-(void)def{
    
    self.delegate = self;
    self.dataSource = self;
    
}

-(void)setUI{
    
}

-(void)setMasonry{
    
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"indexPath == %@",indexPath);
    NSLog(@"");
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    Seach_FiltrateAttribute_Model_WX *model = kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv];
    NSInteger index =  kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child.count;
    return  index;
    
    //    NSLog(@"child = %ld",kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child.count);
    //    return kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    NSArray *arr = kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child[section].data;
    
    return arr.count/3+(arr.count%3==0?0:1);
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self getSeach_FiltrateAttribute_Cell_WX:indexPath];
    
}
-(UITableViewCell *)getSeach_FiltrateAttribute_Cell_WX:(NSIndexPath *)indexPath{
    static NSString *sectionCell = @"Seach_FiltrateAttributeSup_Cell_WX";
    Seach_FiltrateAttributeSup_Cell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[Seach_FiltrateAttributeSup_Cell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.indexPath = indexPath;
    cell.indexTbv = self.indexTbv;
    [cell funcRefloadCell];
    
    //        cell.arr =
    return cell;
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    BaseView *view = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 30+20)];
    [self setHeaderView:view section:section];
    //    [[view addTag]subscribeNext:^(id  _Nullable x) {
    //        NSLog(@"123");
    //        self.priceBtn.selected = !self.priceBtn.selected;
    //        self.priceTtitleBtn.selected = !self.priceTtitleBtn.selected;
    //        [self  reloadData];
    //    }];
    return view;
}

-(void)setHeaderView:(UIView*)supview section:(NSInteger)section{
    
    BaseView *view = [[BaseView alloc]initWithFrame:CGRectMake(0, 20, 4, 16)];
    view.backgroundColor = baseColorTheme;
    [supview addSubview:view];
    
    
    QMUILabel *lab  =[[QMUILabel alloc]initWithFrame:CGRectMake(15, 20, SCREEN_WIDTH-40, 15)];
    lab.text =[NSString stringWithFormat:@"%@",kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child[section].groupName];
    [UIFont fontWithName:@"PingFangSC-Semibold" size:13];
    //    lab.centerY = view.centerY;
    lab.textColor = [UIColor colorWithHex:@"333333"];
    
    lab.text = kUSER_Filtrate_MANAGER.arrAttribute[self.indexTbv].child[section].groupName;
    [supview addSubview:lab];
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat heightCell = 0;
    /* TODO: ================= cell 高度通过类型区分 =================*/
    
    heightCell = 44;
    
    return heightCell;
}

//设置区头不悬浮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat sectionHeaderHeight = 50;
    
    if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0,0);
        
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
    
}

-(void)setIndexTbv:(NSInteger)indexTbv{
    _indexTbv = indexTbv;
    [self reloadData];
}

@end
